package com.petshop.controller;

import com.petshop.pojo.Pets;
import com.petshop.service.PetsService;
import com.petshop.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("pets")
@CrossOrigin
public class PetsController {
    @Autowired
    private PetsService petsService;

    /*
    增加一条宠物信息
     */
    @PostMapping("insertPet")
    public Result insertPet(@RequestBody Pets pets) {
        Result result = petsService.insertPet(pets);
        return result;
    }

    /*
    根据id删除一条宠物信息
     */
    @GetMapping("deletePetById")
    public Result deletePetById(Integer petId) {
        Result result = petsService.deletePetById(petId);
        return result;
    }

    /*
    修改宠物信息
     */
    @PostMapping("updatePet")
    public Result updatePet(@RequestBody Pets pets) {
        Result result = petsService.updatePet(pets);
        return result;
    }

    /*
    查询全部宠物信息
     */
    @GetMapping("queryAllPet")
    public Result queryAllPet() {
        Result result = petsService.queryAllPet();
        return result;
    }

    /*
    根据宠物id查询宠物信息
     */
    @GetMapping("queryPet")
    public Result queryPetById(Integer petId) {
        Result result = petsService.queryPet(petId);
        return result;
    }

    /*
    根据宠物名字模糊查询宠物信息
     */
    @GetMapping("queryPetByName")
    public Result queryPetByName(String name) {
        Result result = petsService.queryPetByName(name);
        return result;
    }
}
